﻿@model Fap.AspNetCore.ViewModel.JqGridViewModel
@using Fap.AspNetCore.Controls.JqGrid
@{
    Layout = null;
    Fap.Workflow.Model.WfBusiness biz = ViewBag.WfBusiness;
    Fap.Workflow.Model.WfProcess wfProcess = ViewBag.WfProcess;
    string tableName = biz.BillEntity;
    string bizCode = biz.BizCode;
    string businessUid = biz.Fid;
    string title = biz.BizName;
    IEnumerable<Fap.Core.Infrastructure.Metadata.FapDict> billStatus = _dbContext.Dictionarys("BillStatus");
    //增加操作列
    Column column = new Column("oper");
    column.SetLabel("操作");
    column.SetSortable(false);
    column.SetWidth(140);
}
<script>
    //刷新列表
    function refreshList() {
           var billstatus = $("#filterStatus").data("billstatus");
        var filter = { groupOp: "AND", rules: [] };
        var rules = [];
        if (billstatus != "-1") {
            rules.push({ field: "BillStatus", op: "eq", data: billstatus });
            filter.rules = rules;
            reloadGrid("grid-@tableName", { filters: JSON.stringify(filter) });
        } else {
            reloadGrid("grid-@tableName");
        }
    }

</script>
<div class="widget-box">
    <div class="widget-header widget-header-flat">
        <h4 class="widget-title smaller">@biz.BizName</h4>

        <div class="widget-toolbar">
            <label>
                <i class="ace-icon fa fa-filter icon-on-right"></i>
                <fap-multilang lang-key="bill_status" default-content="单据状态"></fap-multilang>:
            </label>
            <button data-toggle="dropdown" id="filterStatus" data-billstatus="-1" class="btn  btn-link  dropdown-toggle">
                <fap-multilang lang-key="all_status" default-content="全部状态"></fap-multilang>
                <i class="ace-icon fa fa-angle-down icon-on-right"></i>
            </button>
            <ul class="dropdown-menu dropdown-default" id="btnBillStatus">
                <li data-billstatus="-1">
                    <a href="javascript:void(0)"> <fap-multilang lang-key="all_status" default-content="全部状态"></fap-multilang></a>
                </li>
                @foreach (var item in billStatus)
                {
                    <li data-billstatus="@item.Code">
                        <a href="javascript:void(0)">@item.Name</a>
                    </li>
                }
            </ul>

        </div>
    </div>

    <div class="widget-body">
        <div class="widget-main">
            <fap-grid id="@tableName" attach-column="@column" grid-model="Model" auto-width="true" shrink-fit="false" view-records="true" on-grid-complete="initWorkflowMenu"></fap-grid>
        </div>
    </div>
</div>

<script>
    /**
     * 初始化列表菜单
     * */
    function initWorkflowMenu()
    {
        var ids = jQuery("#grid-@tableName").jqGrid('getDataIDs');
        for (var i = 0; i < ids.length; i++) {
            var de = '';
            var cl = ids[i];
            var ret = jQuery('#grid-@tableName').jqGrid('getRowData', cl);
            var fid = ret.Fid;
            var status = ret.BillStatus;

            //其他不为作废的单子
            de += "<a  href='javascript:void(0)' onclick='viewBill(\"@wfProcess.Fid\",\"@businessUid\",\"" + fid + "\")'>"+$.lang("view","查看")+"</a>  ";
            if (status === 'PROCESSING') {
                //流程中
                de += "<a  href='javascript:void(0)' onclick='urgeBill(\"" + fid + "\")'>"+$.lang("urge","催办")+"</a>  ";
            }
            de += "<a  href='javascript:void(0)' onclick='workflowChart(\"@wfProcess.Fid\",\"" + fid + "\")'>"+$.lang("flow_diagram","流程图")+"</a>  ";

            jQuery('#grid-@tableName').jqGrid('setRowData', ids[i], { oper: de });
        }
    }
    /**
     * 催办
     * @@param fid
     */
    function urgeBill(fid) {
        bootbox.confirm('催办将向处理人发送消息，确认催办？', function (result) {
            if (result) {
                var businessUid = '@businessUid';
                var url = $.randomUrl(basePath + "/Workflow/Api/Business/UrgeBill?billUid=" + fid + "&businnessUid=" + businessUid);
                $.get(url, function (rv) {
                    $.msg(rv.msg);
                })
            }
        })
    }

    jQuery(function ($) {
        $("#btnBillStatus>li").off(ace.click_event).on(ace.click_event, function (e) {
            var tName = $(this).text();
            var tValue = $(this).data("billstatus");
            $("#filterStatus").data("billstatus", tValue);
            $("#filterStatus").html(tName + "<i class=\"ace-icon fa fa-angle-down icon-on-right\"></i>");
            refreshList();
        });
        $(document).one('ajaxloadstart.page', function (e) {
            //$(document).off(ace.click_event, '.dropdown-menu>li');
        })
        //新申请
        $("#btnAddApply").on(ace.click_event, function () {
            //流程模板
            openBillForm('');
        });


    })


</script>